<template>
	<view class="login">
		<view>
			<u--input placeholder="请输入绑定的手机号" border="surround" v-model="phone"></u--input>
		</view>
		<view>
			<u-button type="primary" text="确定" @tap="$u.debounce(register,1000)"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				openid: '',
				img: '',
			};
		},
		methods: {
			register() {
				console.log(this.openid)
				let uservo = {
					phone: this.phone,
					openid: this.openid,
					img: this.img
				}
				uni.request({
					url: "http://172.18.48.131:9527/TN-USER/user/wx/register",
					method: 'POST',
					header: {
						'content-type': "application/json",
					},
					data: uservo,
					success: res => {
						// 请求成功后的回调函数
						uni.showToast({
							title: res.data.msg, // 成功提示消息内容
							icon: 'none',
							duration: 2000, // 提示框显示时间，单位为毫秒，设置为 2000 毫秒（2秒）
							success: () => {
								// 提示框显示 2 秒后执行以下代码
								setTimeout(() => {
									if (res.data.code == 1) {
										uni.reLaunch({
											url: "/pages/login/login"
										});
									}
								}, 2000); // 2秒后执行
							}
						});
					},
				})
			},
			onLoad(option) {
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.on('argParams', (data) => {
					this.openid = data.openid,
						console.log(this.openid)
					this.img = data.img
				})
			}
		}
	}
</script>

<style lang="scss">
	.login {
		width: 96%;
		box-shadow: rgba(14, 30, 37, 0.12) 0px 2px 4px 0px, rgba(14, 30, 37, 0.32) 0px 2px 16px 0px;
	}
</style>